﻿using System;
using System.ComponentModel;
using System.Xml.Serialization;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames
{
    [Serializable]
    [DesignerCategory("code")]
    [XmlType(Namespace = "http://www.blizzard.com/wow/ui/")]
    [XmlRoot(Namespace = "http://www.blizzard.com/wow/ui/", IsNullable = false)]
    public class ScrollFrame : Frame
    {
        /// <summary>
        /// Gets or sets the scroll children of the scroll frame.
        /// Only <see cref="Frame"/>s and <see cref="EditBox"/>es are allowed.
        /// </summary>
        [XmlArray("ScrollChild")]
        [XmlArrayItem("Frame", typeof(Frame))]
        [XmlArrayItem("EditBox", typeof(EditBox))]
        [Category("Behavior")]
        [Description("Gets or sets the scroll children of the scroll frame. Only Frames and EditBoxes are allowed.")]
        public Frame[] ScrollChildren
        {
            get { return Properties.GetValue<Frame[]>("ScrollChildren"); }
            set { Properties.SetValue("ScrollChildren", value); }
        }

        /// <summary>
        /// Gets or sets the scroll child of the scroll frame.
        /// This property is not serialized and wraps <see cref="ScrollChildren"/>.
        /// </summary>
        [XmlIgnore]
        [Browsable(false)]
        public Frame ScrollChild
        {
            get
            {
                if (ScrollChildren != null && ScrollChildren.Length > 0)
                    return ScrollChildren[0];

                return null;
            }
            set { this.ScrollChildren = new[] {value}; }
        }
    }
}